# Makefile.in for sep-library

# Macros

CC          =  @CC@
CFLAGS      =  @CFLAGS@ @INLINE@ @C99@ #@OMPFLAG@ 
RANLIB      =  @RANLIB@
SEPMPI      =  #@SEPMPI@
AR          =  @AR@ 
COMPLEX     =  @COMPLEX@
OMP         =  @OMP@
PREFIX      =  /usr/local/
OBJECT0     =  sepmisc.o seputil.o separray.o sepinit.o sepprfrc.o sepintgr.o \
	       sepret.o sepmol.o sepcoulomb.o sepsampler.o	
PRGS0       =  test/prg0 test/prg1 test/prg2 test/prg3 test/prg4 test/prg5
TOOLS       =  tools/sep_sfg tools/sep_augxyz tools/sep_bcc tools/sep_ctop tools/sep_gettype tools/avotosep tools/sep_eval_smavacf tools/sep_eval_mrdf \
	       tools/sep_eval_pmi
MARCH       =  
MPIINCLUDE  = 
MPILIB      = 


ifeq ($(SEPMPI), YES)
OBJECT1  = $(OBJECT0) sepmpitype.o sepmpi.o
PRGS1    = $(PRGS0) prg3
else
OBJECT1  = $(OBJECT0)
PRGS1    = $(PRGS0)
endif

OBJECTS = $(OBJECT1)
PRGS    = $(PRGS1)

# all
all: libsep.a test tools doc

# Buildning library
libsep.a: $(OBJECTS)
	$(AR) r libsep.a $(OBJECTS) 
	$(RANLIB) libsep.a
	cp libsep.a *.o lib/

%.o:source/%.c 
	$(CC) $(COMPLEX) $(OMP) -c $(CFLAGS) -W -Wall -Iinclude/ $<

# Parallel module - not in the 'trunk' too be removed 
%.o:mpi/%.c 
ifeq ($(SEPMPI), YES)
	mpicc -c $(CFLAGS) $(COMPLEX) $(OMP) -Iinclude/ $<
endif	

# Install (root only)
install: libsep.a
	cp include/*.h $(PREFIX)include/
	cp lib/libsep.a $(PREFIX)lib/

# Cleaning up
clean: 
	rm -f libsep.a *.o
	rm -f lib/*.o lib/*.a
	rm -f $(PRGS)
	rm -f source/*~
	rm -f include/*~
	rm -f mpi/*~
	rm -f doc/*~
	rm -f prgs/*~
	rm -f mydoc/*~
	rm -f *~
	rm -f $(TOOLS)

# Compiling programmes
test: $(PRGS0)

test/%:prgs/%.c
	$(CC) $(CFLAGS) $(OMP) -o $@ -Llib/ -Iinclude $^ -lsep -lm


# Compiling tools
tools: $(TOOLS)

tools/%: tools/%.c
	$(CC) -std=c99 -fopenmp -W -Wall -O2 -pedantic -Wno-unused-result -Iinclude -c tools/septools.c 
	$(CC) -std=c99 -fopenmp -W -Wall -O2 -pedantic -Wno-unused-result -Llib/ -Iinclude septools.o -o $@  $^ -lsep -lm

# document
doc: doc/latex/tutorial.tex
	pdflatex doc/latex/tutorial.tex
